package com.jsmy.marketing.utils;

import android.content.Context;
import android.os.Environment;

import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory;
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
import com.bumptech.glide.module.AppGlideModule;

/**
 * Created with Android Studio.
 * User: wei_cd.
 * Date: 2018/5/2.
 * Time: 11:10.
 * To change for file | settings | file and code templates.
 */

@GlideModule
public class CustomGlideModule extends AppGlideModule {
    private static final String TAG = "AppGlideModule";
    @Override
    public boolean isManifestParsingEnabled() {
        return false;
    }

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        int diskCacheSizeBytes = 1024 * 1024 * 100; // 100 MB
        //判断SD卡是否可用
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
                || !Environment.isExternalStorageRemovable()) {
            L.e(TAG,"External cache");
            builder.setDiskCache(new ExternalPreferredCacheDiskCacheFactory(context, "glidecache", diskCacheSizeBytes));
        } else {
            //没内存卡就存机身内存
            L.e(TAG,"Internal cache");
            builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glidecache", diskCacheSizeBytes));
        }
    }
}
